import {connect, useNavigate} from "umi";
import CheckListWithSearch from "@/components/CheckListWithSearch";

const FeeOrgPage = ({dispatch, feeOrg}) => {
    const navigate = useNavigate();

    const handleCheck = (value) => {
        console.log(value)
        if (value) {
            const feeOrg = value[0];
            navigate("/", {
                state: {
                    feeOrg: {
                        id: feeOrg.id,
                        name: feeOrg.name,
                        code: feeOrg.code
                    },
                }
            })
        }

    }

    const handleSearch = (v) => {
        dispatch({
            type: 'feeOrg/setSearchText',
            payload: {
                value: v
            }
        });
    }


    return (
        <CheckListWithSearch data={feeOrg.list} searchText={feeOrg.searchText} onCheck={v => handleCheck(v)}
                             onSearch={v => handleSearch(v)}/>
    );

};

export default connect(feeOrg => feeOrg)(FeeOrgPage);
